
//TeamOKRevaluates JavaScript
$(function () {
    //总经理评审
    var coefficient = $("#Control20");   //绩效系数
    var coefficientLevel = $("#ctl423381");  //绩效等级

    //绩效等级改变 值不对应清空绩效系数
    coefficientLevel.change(function () {
        var coefLevel = $.MvcSheetUI.GetControlValue("performanceRate"); //绩效等级
        var coefVal = $.MvcSheetUI.GetControlValue("coefficient");  //绩效值
        //转换为浮点数
        var coefValFloat = parseFloat(coefVal);

        switch (coefLevel) {
            case 'A':
                if (coefValFloat < 1.6 || coefValFloat > 2.0) {
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                }
                break;
            case 'B+':
                if (coefValFloat < 1.3 || coefValFloat > 1.55) {
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                }
                break;
            case 'B':
                if (coefValFloat < 1.1 || coefValFloat > 1.25) {
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                }
                break;
            case 'C':
                if (coefValFloat < 0.6 || coefValFloat > 1.0) {
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                }
                break;
            case 'D':
                if (coefValFloat < 0 || coefValFloat > 0.55) {
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                }
                break;
        }


    })

    coefficient.change(function () {
        var coefLevel = $.MvcSheetUI.GetControlValue("performanceRate"); //绩效等级
        var coefVal = $.MvcSheetUI.GetControlValue("coefficient");  //绩效值
        //转换为浮点数
        var coefValFloat = parseFloat(coefVal);

        switch (coefLevel) {
            case 'A':
                if (coefValFloat < 1.6 || coefValFloat > 2.0) {
                    alert("A绩效系数范围为:1.6-2.0,请重新填写");
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                    coefficientLevel.css("border", "1px solid red");
                }
                break;
            case 'B+':
                if (coefValFloat < 1.3 || coefValFloat > 1.55) {
                    alert("B绩效系数范围为:1.3-1.5,请重新填写");
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                    coefficientLevel.css("border", "1px solid red");
                }
                break;
            case 'B':
                if (coefValFloat < 1.1 || coefValFloat > 1.25) {
                    alert("B绩效系数范围为:1.1-1.2,请重新填写");
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                    coefficientLevel.css("border", "1px solid red");
                }
                break;
            case 'C':
                if (coefValFloat < 0.6 || coefValFloat > 1.0) {
                    alert("C绩效系数范围为:0.6-1.0,请重新填写");
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                    coefficientLevel.css("border", "1px solid red");
                }
                break;
            case 'D':
                if (coefValFloat < 0 || coefValFloat > 0.55) {
                    alert("D绩效系数范围为:0-0.55,请重新填写");
                    $.MvcSheetUI.SetControlValue("coefficient", "");
                    coefficientLevel.css("border", "1px solid red");
                }
                break;
        }
    })
})


//PersonalOKRreviews JavaScript
$(function () {

    $.MvcSheet.Loaded = function () {
        var nowActivityCode = $.MvcSheetUI.SheetInfo.ActivityCode;

        //隐藏评估人
        if (IsMobile) {
            $("body").find("div[data-field='commentAtTotal.Assessors']").hide();
        } else {
            $("table").find("td[data-field='commentAtTotal.Assessors']").hide();
        }

        //手工节点
        if (nowActivityCode == "Activity2") {

            var teamLeaderElem = $.MvcSheetUI.GetElement("teamLeader1").SheetGridView();

            if (teamLeaderElem.RowCount <= 1) {

                //先清空
                //清空表
                if (IsMobile) {
                    $("div[data-datafield='teamLeader1']").find(".delete").click()
                } else {
                    if (teamLeaderElem.RowCount != 0) {
                        teamLeaderElem._Clear();
                    }
                }

                //添加行
                if (IsMobile) {
                    teamLeaderElem.addbtnBottom.click();
                    teamLeaderElem.addbtnBottom.click();
                    teamLeaderElem.addbtnBottom.click();
                    teamLeaderElem.addbtnBottom.click();
                } else {
                    teamLeaderElem.addbtn.click();
                    teamLeaderElem.addbtn.click();
                    teamLeaderElem.addbtn.click();
                    teamLeaderElem.addbtn.click();
                }
                //赋值
                $.MvcSheetUI.SetControlValue("teamLeader1.item", "战略推动及贡献", 1);
                $.MvcSheetUI.SetControlValue("teamLeader1.item", "员工管理和团队建设", 2);
                $.MvcSheetUI.SetControlValue("teamLeader1.item", "质量体系维护和流程推进", 3);
                $.MvcSheetUI.SetControlValue("teamLeader1.item", "个人学习与成长", 4);

            }

        }


        if (nowActivityCode == "Activity3" || nowActivityCode == "Activity4" || nowActivityCode == "Activity19") {
            var nowInstanceId = $.MvcSheetUI.SheetInfo.InstanceId;
            var nowLoginPerson = $.MvcSheetUI.SheetInfo.UserName;

            $.ajax({
                url: $.MvcSheetUI.PortalRoot + "/InstanceDetail/GetInstanceStateInfo?InstanceID=" + nowInstanceId,
                type: 'GET',
                dataType: 'json',
                async: false,
                success: function (data) {
                    var authPersonName = "";
                    var instanceInfo = data.Extend.InstanceLogInfo;

                    for (var i = 0; i < instanceInfo.length; i++) {
                        if (instanceInfo[i].ActivityName == "团队负责人最终评估") {
                            authPersonName = instanceInfo[i].ParticipantName;
                        }
                    }

                    if (null != authPersonName && authPersonName != "") {

                        console.log(authPersonName);
                        if (nowLoginPerson == authPersonName) {
                            //拥有查看权限
                            console.log(nowLoginPerson + "拥有查看权限");
                            if (IsMobile) {
                                $("body").find("div[data-field='commentAtTotal.Assessors']").show();
                            } else {
                                $("table").find("td[data-field='commentAtTotal.Assessors']").show();
                            }

                        } else {
                            if (IsMobile) {
                                $("body").find("div[data-field='commentAtTotal.Assessors']").hide();
                            } else {
                                $("table").find("td[data-field='commentAtTotal.Assessors']").hide();
                            }
                        }

                    }


                }
            })

        }
    }

    //提交前事件
    $.MvcSheet.Validate = function () {

        var nowActivityCode = $.MvcSheetUI.SheetInfo.ActivityCode;

        if (nowActivityCode == "Activity2") {
            var atTeamPerson = $.MvcSheetUI.GetControlValue("ATteamParticipant");
            var commentPersonElem = $.MvcSheetUI.GetElement("commentAtTotal").SheetGridView();

            //清空表
            if (IsMobile) {
                $("div[data-datafield='commentAtTotal']").find(".delete").click()
            } else {
                if (commentPersonElem.RowCount != 0) {
                    commentPersonElem._Clear();
                }
            }

            for (var i = 0; i < atTeamPerson.length; i++) {

                //添加行
                if (IsMobile) {
                    commentPersonElem.addbtnBottom.click();
                } else {
                    commentPersonElem.addbtn.click();
                }

                $.MvcSheetUI.SetControlValue("commentAtTotal.Assessors", atTeamPerson[i], (i + 1));

            }

        }

    }


})
